package com.betterjr.modules.application;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.betterjr.common.web.ControllerExceptionHandler;
import com.betterjr.common.web.ControllerExceptionHandler.ExceptionHandler;
import com.betterjr.common.web.Servlets;

/**
 * 
 * @ClassName: ApplicationCustRoleController 
 * @Description: 企业角色应用表servlet入口 
 * @author xuyp
 * @date 2017年11月21日 上午10:16:01 
 *
 */
@Controller
@RequestMapping(value = "/Platform/ApplicationCustRole")
public class ApplicationCustRoleController {

    private static final Logger logger = LoggerFactory.getLogger(ApplicationCustRoleController.class);

    @Reference(interfaceClass = IApplicationCustRoleService.class)
    private IApplicationCustRoleService applicationCustRoleService;

    /**
     * 
     * @Title: saveUpdateApplicationCustRole 
     * @Description: 新增或者修改企业角色应用表信息
     * @param request 
     * @param custNo 企业编号
     * @param roleId  角色id
     * @param applicationIds 应用id集合
     * @return TODO(说明)
     * @throws 
     * @author xuyp
     * @date 2017年11月21日 上午10:08:47
     */
    @RequestMapping(value = "/saveUpdateApplicationCustRole", method = RequestMethod.POST)
    public @ResponseBody String saveUpdateApplicationCustRole(final HttpServletRequest request, Long custNo,
            Long roleId, String applicationIds) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationCustRoleService.webSaveUpdateApplicationCustRole(custNo, roleId, applicationIds);
            }
        }, "操作失败", logger);
    }

    /**
     * 
     * @Title: queryEffectiveApplicationCustRole 
     * @Description: 查询有效的企业角色应用表信息 
     * @param request
     * @param custNo 企业编号
     * @param roleId 角色id
     * @return list集合
     * @throws 
     * @author xuyp
     * @date 2017年11月21日 上午10:14:13
     */
    @RequestMapping(value = "/queryEffectiveApplicationCustRole", method = RequestMethod.POST)
    public @ResponseBody String queryEffectiveApplicationCustRole(final HttpServletRequest request, Long custNo,
            Long roleId) {
        final Map<String, Object> anMap = Servlets.getParametersStartingWith(request, "");
        logger.info("入参：" + anMap);
        return ControllerExceptionHandler.exec(new ExceptionHandler() {
            @Override
            public String handle() {
                return applicationCustRoleService.webQueryEffectiveApplicationCustRole(custNo, roleId);
            }
        }, "操作失败", logger);
    }
}
